﻿using System;
using System.Web;

namespace YN.Utils.Web
{
    public class FormHelper
    {
        public static string GetStringFormParam(string key)
        {
            return GetStringFormParam(key, string.Empty);
        }
        public static string GetStringFormParam(string key, string defaultValue)
        {
            return HttpContext.Current.Request.Form[key] ?? defaultValue;
        }

        public static int GetIntFormParam(string key)
        {
            return GetIntFormParam(key, 0);
        }
        public static int GetIntFormParam(string key, int defaultValue)
        {
            string value = HttpContext.Current.Request.Form[key];

            return TypeConvert.StringToInt(value, defaultValue);
        }

        public static bool GetBoolFormParam(string key)
        {
            return GetBoolFormParam(key, false);
        }
        public static bool GetBoolFormParam(string key, bool defaultValue)
        {
            string value = HttpContext.Current.Request.Form[key];

            return TypeConvert.StringToBool(value, defaultValue);
        }

        public static DateTime GetDateTimeFormParam(string key)
        {
            return GetDateTimeFormParam(key, DateTime.Now);
        }
        public static DateTime GetDateTimeFormParam(string key, DateTime defaultValue)
        {
            string value = HttpContext.Current.Request.Form[key];

            return TypeConvert.StringToDateTime(value, defaultValue);
        }
    }
}
